package de.listrong.da.tools;

import java.util.HashMap;

public class IdGenerator extends HashMap<String, Integer> {

	private static final long serialVersionUID = -399300299204294113L;
    
	// singleton
	private static IdGenerator instance;

	private IdGenerator() {
	}

	public synchronized static IdGenerator getInstance() {
		if (instance == null) {
			instance = new IdGenerator();
		}
		return instance;
	}

	public int newId(String key) {
		if (this.containsKey(key) == false) {
			this.put(key, 0);
		}
		int maxId = this.get(key);
		maxId++;
		this.put(key, maxId);
		return maxId;
	}

}
